package com.example.dllo.baidumusic.adapter;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.baidumusic.R;

import com.example.dllo.baidumusic.bean.SingdanBean;
import com.example.dllo.baidumusic.nettool.NetTool;

/**
 * Created by dllo on 16/8/16.
 */
public class SingDanAdapter extends RecyclerView.Adapter<SingDanAdapter.MyViewHoder> {
    Context mContext;
    private SingdanBean arrayList;
    private OnitenClickListener onitenClickListener;

    public void setOnitenClickListener(OnitenClickListener onitenClickListener) {
        this.onitenClickListener = onitenClickListener;
    }

    public SingDanAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setArrayList(SingdanBean arrayList) {
        this.arrayList = arrayList;
    }


    @Override
    public MyViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_allsinglist, parent, false);
        MyViewHoder myViewHoder = new MyViewHoder(view);
        return myViewHoder;
    }

    @Override
    public void onBindViewHolder(MyViewHoder holder, final int position) {

        holder.tv.setText(arrayList.getContent().getList().get(position).getTitle());
        NetTool netTool = new NetTool();
        netTool.getImage(arrayList.getContent().getList().get(position).getPic(), holder.img);
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onitenClickListener.onClick(position);
            }
        });


    }

    @Override
    public int getItemCount() {
        return arrayList == null ? 0 : arrayList.getContent().getList().size();
    }


    public class MyViewHoder extends RecyclerView.ViewHolder {
        ImageView img;
        TextView tv;


        public MyViewHoder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.singdan_item_tv);
            img = (ImageView) itemView.findViewById(R.id.singdan_item_img);
        }
    }
}
